﻿using Newtonsoft.Json;
using System;

namespace CMS.Infos
{
    public class Room : ICloneable, IAssignable
    {
        [JsonProperty(PropertyName = "name")]
        public string Name { get; set; }

        [JsonProperty(PropertyName = "building")]
        public string Building { get; set; }

        [JsonProperty(PropertyName = "seat_count", NullValueHandling = NullValueHandling.Ignore)]
        public int SeatCount { get; set; } = 50;

        public object Clone()
        {
            return new Room() { Name = Name, Building = Building, SeatCount = SeatCount };
        }

        public override int GetHashCode()
        {
            return (Name?.GetHashCode() ?? 0) ^ (Building?.GetHashCode() ?? 0) ^ SeatCount;
        }

        public override bool Equals(object obj)
        {
            if (obj is Room room)
            {
                return room.Name == Name && room.Building == Building && room.SeatCount == SeatCount;
            }
            else
            {
                return false;
            }
        }

        public override string ToString()
        {
            return Name;
        }

        public object Assign(object src)
        {
            if (src is Room src2)
            {
                Name = src2.Name;
                Building = src2.Building;
                SeatCount = src2.SeatCount;
            }
            else
            {
                throw new ArgumentException();
            }
            return this;
        }
    }
}
